#include <stdlib.h>
#include <gtk/gtk.h>



void main2(GtkWidget *parent_window,gpointer data)
{
GtkWidget *dialog;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
gint res;
//GtkWindow            *parent_window;
dialog = gtk_file_chooser_dialog_new ("Open File",
                                      parent_window,
                                      action,
                                      ("_Cancel"),
                                      GTK_RESPONSE_CANCEL,
                                      ("_Open"),
                                      GTK_RESPONSE_ACCEPT,
                                      NULL);

res = gtk_dialog_run (GTK_DIALOG (dialog));
if (res == GTK_RESPONSE_ACCEPT)
  {
    char *filename;
    GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
    filename = gtk_file_chooser_get_filename (chooser);
   // fopen (filename,"rw");
    g_free (filename);
  }

gtk_widget_destroy (dialog);}

static void
activate (GtkApplication *app,
          gpointer        user_data)
{
  GtkWidget *window; /* 窗口對象 */
  GtkWidget *button;
  /* 爲 GtkApplication 創建頂層窗口 */
  window = gtk_application_window_new (app);
  button=gtk_button_new_with_label("按钮");
  gtk_container_add(GTK_CONTAINER(window),button);
  /* 設定標題 */
  gtk_window_set_title (GTK_WINDOW (window), "Hello GNOME");
  g_signal_connect(button,"clicked",G_CALLBACK(main2),NULL);
  /* 顯示窗口 */
  gtk_widget_show(button);
  gtk_widget_show_all (GTK_WIDGET (window));

}

int
main (int argc, char **argv)
{
  GtkApplication *app; /* GtkApplication 對象 */
  int status; /* 退出狀態 */

  /* 創建一個 GtkApplication 對象 */
  app = gtk_application_new ("org.gtk.example",G_APPLICATION_FLAGS_NONE);
  /* 將 GtkApplication 中的 "activate" 信號（意爲「激活」）連接到 activate 函數上 */
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  /* 啓動此 GtkApplication，該函數返回時程序應該就已經結束了，以下就是程序收尾階段了 */
  status = g_application_run (G_APPLICATION (app), argc, argv);
   //main2();
  /* 銷毀 GtkApplication */
  g_object_unref (app);
  /* 退出程序，向系統報告返回狀態碼 */
  return status;
}
